import 'dart:math';

import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: AppBar(
          title: Text("basic"),
          centerTitle: true,
        ),
      ),
      body: Content(),
    );
  }
}

class Content extends StatelessWidget {
  const Content({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GridViewDemo01();
  }
}

class GridViewDemo01 extends StatelessWidget {
  const GridViewDemo01({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      //水平方向
      padding: EdgeInsets.symmetric(horizontal: 8),
      child: GridView(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
              //高度
              childAspectRatio: .8,
              //交叉轴间距
              crossAxisSpacing: 8,
              mainAxisSpacing: 8
          ),
          children: List.generate(100, (index){
            return Container(
                color: Color.fromARGB(255, Random().nextInt(256), Random().nextInt(256), Random().nextInt(245))
            );
          })
      ),
    );
  }
}